import 'package:flutter_oldman_health/utils/http_util.dart';

import 'constant.dart';

class AlbumService {
  // 新建相册
  //{
  //     "code" : 0,
  //     "message" : "",
  //     "data" : "272b3f9c76e14e698a4a9a1f86f25dcc" // 相册id
  // }
  static Future createAlbum(String name) async {
    var result = await HttpUtil.post(
        Constant.host + "/manager/medical/albums/${Constant.enterpriseId}",
        data: {"name": name});
    return result;
  }

  // 修改相册
  //{
  //     "code" : 0,
  //     "message" : "",
  //     "data" : "2"
  // }
  static Future updateAlbum(String name, String albumId) async {
    var result = await HttpUtil.put(
        Constant.host +
            "/manager/medical/albums/${Constant.enterpriseId}/$albumId",
        data: {"name": name});
    return result;
  }

  static Future deleteAlbum(String albumId) async {
    var result = await HttpUtil.delete(Constant.host +
        "/manager/medical/albums/${Constant.enterpriseId}/$albumId");

    return result;
  }

  static Future queryAlbumList({String name}) async {
    var result;
    if (null == name) {
      result = await HttpUtil.get(Constant.host +
          "/manager/medical/albums/${Constant.enterpriseId}/list");
    } else {
      result = await HttpUtil.get(
          Constant.host +
              "/manager/medical/albums/${Constant.enterpriseId}/list",
          queryParams: {"name": name});
    }

    return result;
  }

  static Future deletePhoto(String photoId) async {
    var result = await HttpUtil.delete(Constant.host +
        "/manager/medical/albums/${Constant.enterpriseId}/photos/$photoId");

    return result;
  }

  // name 文件名称
  // photoAlbumId 相册id
  // type 类型；1：图片，2：视频；目前只有图片
  // location 上传成功得到的相对路径
  // "data" : "272b3f9c76e14e698a4a9a1f86f25dcc" // 图片id
//保存图片信息
// 此接口在上传图片成功拿到path值（相对路径）时调用
  static Future savePhotoInfo(
      String name, String photoAlbumId, int type, String location) async {
    var result = await HttpUtil.post(
        Constant.host +
            "/manager/medical/albums/${Constant.enterpriseId}/photos",
        data: {
          "name": name,
          "photoAlbumId": photoAlbumId,
          "type": type,
          "location": location
        });

    return result;
  }

  //上传文件
  //   "data" : {
  //         "id" : "xxxxx", // 文件id
  //         "filename" : image.png, // 上传文件名
  //         "size" : 123456, // 大小，单位 B
  //         "path" : "qisyun/xxx/xxx/image.png",  // 图片相对路径
  //         "category" : "health",
  //         "inDate" : 1632973220728 // 上传时间
  //         "inUser" : "2edebb34b6bd4dadb9a4325773a73f50"  // 上传人
  //     }
  // static Future uploadPhoto(File file,
  //     {String fileKey = "MultipartFile", Map<String, dynamic> queryParams}) async {
  //   var result = await HttpUtil.uploadSingle(
  //       Constant.host + '/manager/v3/common/upload/health/file', fileKey, file,
  //       queryParams: queryParams);
  //   return result;
  // }

  static Future uploadPhotoByPath(String filePath,
      {String fileKey = "image"}) async {
    var result = await HttpUtil.uploadByPathSingle(
        Constant.host + '/manager/v3/common/upload/health/file',
        fileKey,
        filePath);
    return result;
  }
}
